//
//  StatusBottomView.swift
//  3月5的项目
//
//  Created by 哦哦 on 16/3/16.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

/*
三等分视图:
1.平铺所有的视图
2.最右边的视图 和最左边的视图 分别添加相对父视图的约束
3.设置等宽
*/

class StatusBottomView: UIView {
    
    //按钮的监听事件
    @objc private func repostBtnDidClikc(){
        //页面跳转
        let temp = TempViewController()
        //设置底部tabbar隐藏
        temp.hidesBottomBarWhenPushed = true
        //使用导航视图控制 跳转页面
        navController()?.pushViewController(temp, animated: true)
        
        
    }
    
    
    
    
    //重写构造方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    //默认实现报错
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: 设置UI界面
    private func setupUI() {
        backgroundColor = UIColor.yellowColor()
//        backgroundColor = UIColor(white: 0.9, alpha: 1)

        addSubview(repostBtn)
        addSubview(commentBtn)
        addSubview(ohYeah)
        
        
        //三个按钮 平分视图
        repostBtn.snp_makeConstraints { (make) -> Void in
            make.top.bottom.left.equalTo(self)
        }
        
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(self)
            make.left.equalTo(repostBtn.snp_right)
            make.width.equalTo(repostBtn.snp_width)
        }
        
        ohYeah.snp_makeConstraints { (make) -> Void in
            make.top.bottom.right.equalTo(self)
            make.left.equalTo(commentBtn.snp_right)
            make.width.equalTo(commentBtn.snp_width)
        }
        let sep1 = sepView()
        
        let sep2 = sepView()
        
        //添加分割线
        addSubview(sep1)
        addSubview(sep2)
        
        let w: CGFloat = 0.8
        
        //设置约束
        sep1.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(repostBtn.snp_right)
            //黄金分割比 1 : 0.618
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.centerY.equalTo(self.snp_centerY)
            //设置宽度
            make.width.equalTo(w)
            
        }
        
        sep2.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentBtn.snp_right)
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.centerY.equalTo(self.snp_centerY)
            //设置宽度
            make.width.equalTo(w)
        }
        
        //添加按钮 的监听事件
        repostBtn.addTarget(self, action: "repostBtnDidClikc", forControlEvents: .TouchUpInside)
        
    }
    
    
    //分割线视图
    private func sepView() -> UIView {
        let lineView = UIView()
        
        //设置背景色
//        lineView.backgroundColor = UIColor.lightGrayColor()
        lineView.backgroundColor = UIColor.blackColor()

        return lineView

        
    }
    
    
    //MARK: 懒加载子视图
    private lazy var repostBtn: UIButton = UIFactory.buttonWithtitle("转发", backImageName: nil, textColor: UIColor.darkGrayColor(), fontSize: 12, imageName: "timeline_icon_retweet")
    private lazy var commentBtn: UIButton = UIFactory.buttonWithtitle("评论", backImageName: nil, textColor: UIColor.darkGrayColor(), fontSize: 12, imageName: "timeline_icon_comment")
    private lazy var ohYeah: UIButton = UIFactory.buttonWithtitle("点赞", backImageName: nil, textColor: UIColor.darkGrayColor(), fontSize: 12, imageName: "timeline_icon_unlike")
    
}
